#pragma once
#include "const.h"
#include "CSession.h"

typedef std::function<void(std::shared_ptr<CSession>, const short& msg_id, const std::string& msg_data)> FuncCallBack;
class LogicSys
{
public:
	static LogicSys& GetInst();
	~LogicSys();
	void PostMsgToQue(std::shared_ptr<LogicNode>);
private:
	std::queue<std::shared_ptr<LogicNode>> _logic_que;
	std::mutex _mtx;
	std::condition_variable _cond_var;
	std::thread  _work_thread;
	std::atomic<bool> _b_stop;
	std::map<short, FuncCallBack> _func_callbacks;
	LogicSys();
	void RegisterCallBack();
	void dealMsg();
	bool isPureDigit(const std::string& str);
	void GetUserByUid(std::string uid_str, Json::Value& rtvalue);
	void GetUserByName(std::string name_str, Json::Value& rtvalue);
	void LoginHandler(std::shared_ptr<CSession>, const short& msg_id, const std::string& msg_data);
	void SearchInfo(std::shared_ptr<CSession>, const short& msg_id, const std::string& msg_data);
	bool GetFriendApplyInfo(int uid, std::vector<std::shared_ptr<ApplyInfo>>& apply_list);
	void AddFriendApply(std::shared_ptr<CSession>, const short& msg_id, const std::string& msg_data);
	void AuthFriendApply(std::shared_ptr<CSession>, const short& msg_id, const std::string& msg_data);
	void DealChatTextMsg(std::shared_ptr<CSession>, const short& msg_id, const std::string& msg_data);
	bool GetBaseInfo(std::string base_key, int uid, std::shared_ptr<UserInfo>& user_info);
	bool GetFriendList(int self_uid, std::vector<std::shared_ptr<UserInfo>>& user_list);
	LogicSys& operator=(const LogicSys&) = delete;
	LogicSys(const LogicSys&) = delete;
};

